<?php
class User_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{
//    public function __construct ()
//    {
//        $this->RoleModel = new User_Model_Acl_Roles();
//        $this->RuleModel = new User_Model_Acl_Rules();
//        $this->acl = new Zend_Acl();
//        $this->user = Zend_Auth::getInstance()->getIdentity();
//        $this->UserModel = new User_Model_User();
//    }
//    public function preDispatch ()
//    {
//        if (empty($this->user)) {
//            $this->user = $this->UserModel->fetchNew();
//            $this->user->role = $this->RoleModel->fetchRow("name = 'guest'");
//        }
//        //debug($this->user);
//        return;
//        $this->roles = $this->rolesModel->fetchAll();
//        foreach ($this->roles as $role)
//            $this->acl->addRole(new Zend_Acl_Role($role->name));
//        $this->rules = $this->rulesModel->findAll();
//        $front = Zend_Controller_Front::getInstance();
//        foreach ($front->getControllerDirectory() as $res_name => $res) {
//            $this->acl->add(new Zend_Acl_Resource($res_name));
//            /* Allow to access to resources for all roles */
//            foreach ($this->roles as $role)
//                $this->acl->allow((string) $role->name, $res_name);
//                /* Deny accesss to resources from database */
//            foreach ($this->rules as $rule) {
//                if (! empty($rule->module) and $res_name == $rule->module) {
//                    $role_name = (string) $rule->role->name;
//                    switch ($rule->rule) {
//                        case 'allow':
//                            $this->acl->allow($role_name, $res_name);
//                            break;
//                        case 'deny':
//                            $this->acl->deny($role_name, $res_name);
//                            break;
//                    }
//                }
//            }
//        }
//        $user = $this->getRequest()->getParam('user');
//        return $this->acl->isAllowed($user->role->name, $params['module']) ? true : false;
//    }
}